const { dateFormat, getActiveStr } = require("../../../utils/utilsNew");

// component/common/com-conversation-item/com-conversation-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model: {
      type: Object,
      default: {},
    },
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _model: {},
    authed: false,
  },

  observers: {
    model(v) {
      let _model = { ...v };
      _model.userProfile.avatar = _model.userProfile.avatar || "/images/default_head.png";
      // 来自他人的消息
      if (_model.lastMessage.fromAccount == _model.userProfile.userID) {
        _model._tips = _model.unreadCount != 0 ? `未读` : "已读";
      } else {
        _model._tips = _model.peerReadTime < _model.lastMessage.lastTime ? `送达` : "已读";
      }

      _model._lastTime = dateFormat(_model.lastMessage.lastTime * 1000);
      _model.lastMessage._messageForShow = getActiveStr(_model.lastMessage.messageForShow, 20)

      this.setData({
        _model,
        authed: _model.profileCustomField && _model.profileCustomField.Tag_Profile_Custom_authed == '1'
      });
    },
  },

  lifetimes: {
    attached: function () {
    },

    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {},
});
